package servlet;

import domain.Product;
import org.apache.log4j.Logger;
import service.ProductService;
import service.impl.ProductServiceImpl;

import javax.jws.WebService;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author admin
 * @Date 2019/2/25 11:19
 */
@WebServlet(name = "findAll" ,urlPatterns = "/findAll")
public class FindAllServlet extends HttpServlet {

    Logger log = Logger.getLogger(FindAllServlet.class);

    ProductService service = new ProductServiceImpl();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, IOException {

        List<Product> list = service.findAll();

        log.debug(list);

        //将数据放在request作用域中
        request.setAttribute("list",list);

        //请求转发到findAll.jsp页面中
        request.getRequestDispatcher("/WEB-INF/pageList.jsp").forward(request,response);
    }

    //debug启动，保证数据已经从数据库中读出
}
